/**
 * Created by Administrator on 2016/7/11.
 */
$(document).ready(function() {
    //个人消息
    if (myinfo['userid'] && myinfo['random']) {

        $('.edit_userinfo .info_name').html(myinfo['nickname']);
        $('.edit_userinfo .info_phone').html(myinfo['phone']);
        $('.edit_userinfo .info_qq').html(myinfo['qq']);
        $('.edit_userinfo .info_email').html(myinfo['email']);
        $('.edit_user_email b').html(myinfo['email']);
        $('#nickname').val(myinfo['nickname']);
        $('#phone').val(myinfo['phone']);
        $('#qq').val(myinfo['qq']);
        $('#email').val(myinfo['email']);

        //$('#phone').val(myinfo['phone']);
        //document.getElementById("nickname").value=myinfo['nickname'];

    } else {
        window.location.href='/templates/user/login.html';
       // $('.userinfo').hide();
        //$('.user').show();
    }
    $(".user_shiming").click(function(){
        if(myinfo['userid'] && myinfo['random']) {
            var save_name=myconfig['api']+'update_identity';
            var userid=myinfo['userid'];
            var random=myinfo['random'];
            var name=document.getElementById("name").value;
            var identity=document.getElementById("id_number").value;
            $.post(save_name,{userid:userid,random:random,name:name,id_number:identity}, function(data,status){
                if(data.status==1){
                   // get_userinfor();
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-smile',
                        title: '提示',
                        content: data.msg,
                        okVal: '确定',
                        ok:function() {

                            window.location.href='/templates/user/profile_shiming.html';
                        }
                    });
                }else{
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-sad',
                        title: '错误提示',
                        content: data.msg,
                        ok: true,

                    });
                }
            },'json');
        }
    });



    $(".name").click(function(){
        if(myinfo['userid'] && myinfo['random']) {
            var save_name=myconfig['api']+'set_user_nickname';
            var userid=myinfo['userid'];
            var random=myinfo['random'];
            var name=document.getElementById("nickname").value;
            $.post(save_name,{userid:userid,random:random,nickname:name}, function(data,status){
                if(data.status==1){
                    get_userinfor();
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-smile',
                        title: '提示',
                        content: data.msg,
                        okVal: '确定',
                        ok:function() {

                            window.location.href='/templates/user/profile.html';
                        }
                    });
                }else{
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-sad',
                        title: '错误提示',
                        content: data.msg,
                        ok: true,

                    });
                }
            },'json');
        }
    });

    $(".qq").click(function(){
        if(myinfo['userid'] && myinfo['random']) {
            var save_name=myconfig['api']+'update_qq';
            var userid=myinfo['userid'];
            var random=myinfo['random'];
            var qq=document.getElementById("qq").value;
            $.post(save_name,{userid:userid,random:random,qq:qq}, function(data,status){
                if(data.status==1){
                    get_userinfor();
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-smile',
                        title: '提示',
                        content: data.msg,
                        okVal: '确定',
                        ok:function() {

                            window.location.href='/templates/user/profile.html';
                        }
                    });
                }else{
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-sad',
                        title: '错误提示',
                        content: data.msg,
                        ok: true,

                    });
                }
            },'json');
        }
    });


    $(".bind_tb").click(function(){
        if(myinfo['userid'] && myinfo['random']) {
            var save_name=myconfig['api']+'bind_tb_info';
            var userid=myinfo['userid'];
            var random=myinfo['random'];
            var taobao=document.getElementById("tb_info").value;
            $.post(save_name,{userid:userid,random:random,account:taobao}, function(data,status){
                if(data.status==1){
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-smile',
                        title: '提示',
                        content: data.msg,
                        okVal: '确定',
                        ok:function() {

                            window.location.href='/templates/user/profile.html';
                        }
                    });
                }else{
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-sad',
                        title: '错误提示',
                        content: data.msg,
                        ok: true

                    });
                }
            },'json');
        }
    });
    $(".email").click(function(){
        if(myinfo['userid'] && myinfo['random']) {
            var save_name=myconfig['api']+'update_email';
            var userid=myinfo['userid'];
            var random=myinfo['random'];
            var code=document.getElementById("code").value;
            var email=document.getElementById("email").value;
            $.post(save_name,{userid:userid,random:random,email:email}, function(data,status){
                if(data.status==1){
                    get_userinfor();
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-smile',
                        title: '提示',
                        content: data.msg,
                        okVal: '确定',
                        ok:function() {

                            window.location.href='/templates/user/profile.html';
                        }
                    });
                }else{
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-sad',
                        title: '错误提示',
                        content: data.msg,
                        ok: true,

                    });
                }
            },'json');
        }
    });
    $(".phone").click(function(){
        if(myinfo['userid'] && myinfo['random']) {
            var save_name=myconfig['api']+'update_phone';
            var userid=myinfo['userid'];
            var random=myinfo['random'];
            var phone=document.getElementById("phone").value;
            var code=document.getElementById("code").value;
            $.post(save_name,{userid:userid,random:random,phone:phone,code:code}, function(data,status){
                if(data.status==1){
                    get_userinfor();
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-smile',
                        title: '提示',
                        content: data.msg,
                        okVal: '确定',
                        ok:function() {

                            window.location.href='/templates/user/profile.html';
                        }
                    });
                }else{
                    art.dialog({
                        lock: true,
                        fixed: true,
                        icon: 'face-sad',
                        title: '错误提示',
                        content: data.msg,
                        ok: true,

                    });
                }
            },'json');
        }
    });

        $(".login_out").click(function() {

        if(myinfo['userid']&& myinfo['random']){

            sessionStorage.clear();
            art.dialog({
                lock: true,
                fixed: true,
                icon: 'face-smile',
                title: '提示',
                content:'退出成功！',
                okVal: '确定',
                ok:function(){
                    window.location.href='/templates/tab_user.html';
                }

            });
        }
        else{
                art.dialog({
                    lock: true,
                    fixed: true,
                    icon: 'face-sad',
                    title: '错误提示',
                    content: '退出失败！',
                    ok: true
                });
        }
    })


});